using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQVW_ABPOS
    {
        public DataRow Convert2QVW_ABPOS(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQVW_ABPOS(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["KAUF"] = " ".PadRight(9 ); 
         dwReturn["AUFTYP"] = " ".PadRight(1 ); 
         dwReturn["PAUF"] = " ".PadRight(12 ); 
         dwReturn["PKRS"] = " ".PadRight(2 ); 
         dwReturn["PLFD"] = " ".PadRight(6 ); 
         dwReturn["PPOS"] = " ".PadRight(3 ); 
         dwReturn["ARTST"] = " ".PadRight(1 ); 
         dwReturn["PART"] = " ".PadRight(20 ); 
         dwReturn["PVAR"] = " ".PadRight(3 ); 
         dwReturn["PCOLOR"] = " ".PadRight(10 ); 
         dwReturn["PDESS"] = " ".PadRight(10 ); 
         dwReturn["PDCWY"] = " ".PadRight(10 ); 
         dwReturn["PFINISH"] = " ".PadRight(10 ); 
         dwReturn["PSIZE"] = " ".PadRight(7 ); 
         dwReturn["COLORGRP"] = " ".PadRight(1 ); 
         dwReturn["PLIEFNR"] = " ".PadRight(8 ); 
         dwReturn["PPMTR"] = " ".PadRight(0 ); 
         dwReturn["PPKG"] = " ".PadRight(0 ); 
         dwReturn["PQTY1"] = " ".PadRight(0 ); 
         dwReturn["PQTY2"] = " ".PadRight(0 ); 
         dwReturn["PQTY3"] = " ".PadRight(0 ); 
         dwReturn["PQTY4"] = " ".PadRight(0 ); 
         dwReturn["PQTY5"] = " ".PadRight(0 ); 
         dwReturn["PQTY6"] = " ".PadRight(0 ); 
         dwReturn["PQTY7"] = " ".PadRight(0 ); 
         dwReturn["PQTY8"] = " ".PadRight(0 ); 
         dwReturn["PEMTR"] = " ".PadRight(0 ); 
         dwReturn["PEKG"] = " ".PadRight(0 ); 
         dwReturn["ABPLIEFDAT"] = " ".PadRight(0 ); 
         dwReturn["DYEAR"] = " ".PadRight(4 ); 
         dwReturn["DMONTH"] = " ".PadRight(2 ); 
         dwReturn["DDAY"] = " ".PadRight(2 ); 
         dwReturn["DQUARTER"] = " ".PadRight(41 ); 
         dwReturn["ABPSTARTDAT"] = " ".PadRight(0 ); 
         dwReturn["BYEAR"] = " ".PadRight(4 ); 
         dwReturn["BMONTH"] = " ".PadRight(2 ); 
         dwReturn["BDAY"] = " ".PadRight(2 ); 
         dwReturn["BQUARTER"] = " ".PadRight(41 ); 
         dwReturn["ABPENDDAT"] = " ".PadRight(0 ); 
         dwReturn["EYEAR"] = " ".PadRight(4 ); 
         dwReturn["EMONTH"] = " ".PadRight(2 ); 
         dwReturn["EDAY"] = " ".PadRight(2 ); 
         dwReturn["EQUARTER"] = " ".PadRight(41 ); 
         dwReturn["PFLOW"] = " ".PadRight(8 ); 
         dwReturn["PSTATUS"] = " ".PadRight(2 ); 
         dwReturn["PSTATUSCODE"] = " ".PadRight(2 ); 
         dwReturn["ABPWSSTA"] = " ".PadRight(2 ); 
         dwReturn["ABPAPSTA"] = " ".PadRight(2 ); 
         dwReturn["ABPRZSTA"] = " ".PadRight(2 ); 
         dwReturn["ABPWPSTA"] = " ".PadRight(2 ); 
         dwReturn["ABPWBSTA"] = " ".PadRight(2 ); 
         dwReturn["ABPABSTA"] = " ".PadRight(2 ); 
         dwReturn["PEND"] = " ".PadRight(1 ); 
         dwReturn["FENDDAT"] = " ".PadRight(0 ); 
         dwReturn["FYEAR"] = " ".PadRight(4 ); 
         dwReturn["FMONTH"] = " ".PadRight(2 ); 
         dwReturn["FDAY"] = " ".PadRight(2 ); 
         dwReturn["FQUARTER"] = " ".PadRight(41 ); 
         dwReturn["PFCOST"] = " ".PadRight(0 ); 
         dwReturn["PMCOST"] = " ".PadRight(0 ); 
         dwReturn["PMBOMCOST"] = " ".PadRight(0 ); 
         dwReturn["PRODCOST"] = " ".PadRight(0 ); 
         dwReturn["PROFIT"] = " ".PadRight(0 ); 
         dwReturn["ARTCOSTKG"] = " ".PadRight(0 ); 
         dwReturn["ARTCOSTMTR"] = " ".PadRight(0 ); 
         dwReturn["ARTCOST"] = " ".PadRight(0 ); 
         dwReturn["FOK"] = " ".PadRight(1 ); 
         dwReturn["RTIME"] = " ".PadRight(0 ); 
         dwReturn["RCOST"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQVW_ABPOS(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQVW_ABPOS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQVW_ABPOS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQVW_ABPOS(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQVW_ABPOS(dwLocal, ITXDBVERSION);
            }
            UpdateQVW_ABPOS(dwLocal);
        }
        public void InsertQVW_ABPOS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QVW_ABPOS(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQVW_ABPOS(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QVW_ABPOS WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QVW_ABPOS  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QVW_ABPOS";
            Return = Result;
            return Return;
        }
        public void DeleteQVW_ABPOS(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QVW_ABPOS   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQVW_ABPOS(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QVW_ABPOS SET "
                    +"KAUF= :KAUF,"
                    +"AUFTYP= :AUFTYP,"
                    +"PAUF= :PAUF,"
                    +"PKRS= :PKRS,"
                    +"PLFD= :PLFD,"
                    +"PPOS= :PPOS,"
                    +"ARTST= :ARTST,"
                    +"PART= :PART,"
                    +"PVAR= :PVAR,"
                    +"PCOLOR= :PCOLOR,"
                    +"PDESS= :PDESS,"
                    +"PDCWY= :PDCWY,"
                    +"PFINISH= :PFINISH,"
                    +"PSIZE= :PSIZE,"
                    +"COLORGRP= :COLORGRP,"
                    +"PLIEFNR= :PLIEFNR,"
                    +"PPMTR= :PPMTR,"
                    +"PPKG= :PPKG,"
                    +"PQTY1= :PQTY1,"
                    +"PQTY2= :PQTY2,"
                    +"PQTY3= :PQTY3,"
                    +"PQTY4= :PQTY4,"
                    +"PQTY5= :PQTY5,"
                    +"PQTY6= :PQTY6,"
                    +"PQTY7= :PQTY7,"
                    +"PQTY8= :PQTY8,"
                    +"PEMTR= :PEMTR,"
                    +"PEKG= :PEKG,"
                    +"ABPLIEFDAT= :ABPLIEFDAT,"
                    +"DYEAR= :DYEAR,"
                    +"DMONTH= :DMONTH,"
                    +"DDAY= :DDAY,"
                    +"DQUARTER= :DQUARTER,"
                    +"ABPSTARTDAT= :ABPSTARTDAT,"
                    +"BYEAR= :BYEAR,"
                    +"BMONTH= :BMONTH,"
                    +"BDAY= :BDAY,"
                    +"BQUARTER= :BQUARTER,"
                    +"ABPENDDAT= :ABPENDDAT,"
                    +"EYEAR= :EYEAR,"
                    +"EMONTH= :EMONTH,"
                    +"EDAY= :EDAY,"
                    +"EQUARTER= :EQUARTER,"
                    +"PFLOW= :PFLOW,"
                    +"PSTATUS= :PSTATUS,"
                    +"PSTATUSCODE= :PSTATUSCODE,"
                    +"ABPWSSTA= :ABPWSSTA,"
                    +"ABPAPSTA= :ABPAPSTA,"
                    +"ABPRZSTA= :ABPRZSTA,"
                    +"ABPWPSTA= :ABPWPSTA,"
                    +"ABPWBSTA= :ABPWBSTA,"
                    +"ABPABSTA= :ABPABSTA,"
                    +"PEND= :PEND,"
                    +"FENDDAT= :FENDDAT,"
                    +"FYEAR= :FYEAR,"
                    +"FMONTH= :FMONTH,"
                    +"FDAY= :FDAY,"
                    +"FQUARTER= :FQUARTER,"
                    +"PFCOST= :PFCOST,"
                    +"PMCOST= :PMCOST,"
                    +"PMBOMCOST= :PMBOMCOST,"
                    +"PRODCOST= :PRODCOST,"
                    +"PROFIT= :PROFIT,"
                    +"ARTCOSTKG= :ARTCOSTKG,"
                    +"ARTCOSTMTR= :ARTCOSTMTR,"
                    +"ARTCOST= :ARTCOST,"
                    +"FOK= :FOK,"
                    +"RTIME= :RTIME,"
                    +"RCOST= :RCOST,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("KAUF", OracleType.NVarChar).Value = dwData["KAUF"].ToString(); 
          or1.Parameters.Add("AUFTYP", OracleType.NVarChar).Value = dwData["AUFTYP"].ToString(); 
          or1.Parameters.Add("PAUF", OracleType.NVarChar).Value = dwData["PAUF"].ToString(); 
          or1.Parameters.Add("PKRS", OracleType.NVarChar).Value = dwData["PKRS"].ToString(); 
          or1.Parameters.Add("PLFD", OracleType.NVarChar).Value = dwData["PLFD"].ToString(); 
          or1.Parameters.Add("PPOS", OracleType.NVarChar).Value = dwData["PPOS"].ToString(); 
          or1.Parameters.Add("ARTST", OracleType.NVarChar).Value = dwData["ARTST"].ToString(); 
          or1.Parameters.Add("PART", OracleType.NVarChar).Value = dwData["PART"].ToString(); 
          or1.Parameters.Add("PVAR", OracleType.NVarChar).Value = dwData["PVAR"].ToString(); 
          or1.Parameters.Add("PCOLOR", OracleType.NVarChar).Value = dwData["PCOLOR"].ToString(); 
          or1.Parameters.Add("PDESS", OracleType.NVarChar).Value = dwData["PDESS"].ToString(); 
          or1.Parameters.Add("PDCWY", OracleType.NVarChar).Value = dwData["PDCWY"].ToString(); 
          or1.Parameters.Add("PFINISH", OracleType.NVarChar).Value = dwData["PFINISH"].ToString(); 
          or1.Parameters.Add("PSIZE", OracleType.NVarChar).Value = dwData["PSIZE"].ToString(); 
          or1.Parameters.Add("COLORGRP", OracleType.NVarChar).Value = dwData["COLORGRP"].ToString(); 
          or1.Parameters.Add("PLIEFNR", OracleType.NVarChar).Value = dwData["PLIEFNR"].ToString(); 
          or1.Parameters.Add("PPMTR", OracleType.NVarChar).Value = dwData["PPMTR"].ToString(); 
          or1.Parameters.Add("PPKG", OracleType.NVarChar).Value = dwData["PPKG"].ToString(); 
          or1.Parameters.Add("PQTY1", OracleType.NVarChar).Value = dwData["PQTY1"].ToString(); 
          or1.Parameters.Add("PQTY2", OracleType.NVarChar).Value = dwData["PQTY2"].ToString(); 
          or1.Parameters.Add("PQTY3", OracleType.NVarChar).Value = dwData["PQTY3"].ToString(); 
          or1.Parameters.Add("PQTY4", OracleType.NVarChar).Value = dwData["PQTY4"].ToString(); 
          or1.Parameters.Add("PQTY5", OracleType.NVarChar).Value = dwData["PQTY5"].ToString(); 
          or1.Parameters.Add("PQTY6", OracleType.NVarChar).Value = dwData["PQTY6"].ToString(); 
          or1.Parameters.Add("PQTY7", OracleType.NVarChar).Value = dwData["PQTY7"].ToString(); 
          or1.Parameters.Add("PQTY8", OracleType.NVarChar).Value = dwData["PQTY8"].ToString(); 
          or1.Parameters.Add("PEMTR", OracleType.NVarChar).Value = dwData["PEMTR"].ToString(); 
          or1.Parameters.Add("PEKG", OracleType.NVarChar).Value = dwData["PEKG"].ToString(); 
          or1.Parameters.Add("ABPLIEFDAT", OracleType.NVarChar).Value = dwData["ABPLIEFDAT"].ToString(); 
          or1.Parameters.Add("DYEAR", OracleType.NVarChar).Value = dwData["DYEAR"].ToString(); 
          or1.Parameters.Add("DMONTH", OracleType.NVarChar).Value = dwData["DMONTH"].ToString(); 
          or1.Parameters.Add("DDAY", OracleType.NVarChar).Value = dwData["DDAY"].ToString(); 
          or1.Parameters.Add("DQUARTER", OracleType.NVarChar).Value = dwData["DQUARTER"].ToString(); 
          or1.Parameters.Add("ABPSTARTDAT", OracleType.NVarChar).Value = dwData["ABPSTARTDAT"].ToString(); 
          or1.Parameters.Add("BYEAR", OracleType.NVarChar).Value = dwData["BYEAR"].ToString(); 
          or1.Parameters.Add("BMONTH", OracleType.NVarChar).Value = dwData["BMONTH"].ToString(); 
          or1.Parameters.Add("BDAY", OracleType.NVarChar).Value = dwData["BDAY"].ToString(); 
          or1.Parameters.Add("BQUARTER", OracleType.NVarChar).Value = dwData["BQUARTER"].ToString(); 
          or1.Parameters.Add("ABPENDDAT", OracleType.NVarChar).Value = dwData["ABPENDDAT"].ToString(); 
          or1.Parameters.Add("EYEAR", OracleType.NVarChar).Value = dwData["EYEAR"].ToString(); 
          or1.Parameters.Add("EMONTH", OracleType.NVarChar).Value = dwData["EMONTH"].ToString(); 
          or1.Parameters.Add("EDAY", OracleType.NVarChar).Value = dwData["EDAY"].ToString(); 
          or1.Parameters.Add("EQUARTER", OracleType.NVarChar).Value = dwData["EQUARTER"].ToString(); 
          or1.Parameters.Add("PFLOW", OracleType.NVarChar).Value = dwData["PFLOW"].ToString(); 
          or1.Parameters.Add("PSTATUS", OracleType.NVarChar).Value = dwData["PSTATUS"].ToString(); 
          or1.Parameters.Add("PSTATUSCODE", OracleType.NVarChar).Value = dwData["PSTATUSCODE"].ToString(); 
          or1.Parameters.Add("ABPWSSTA", OracleType.NVarChar).Value = dwData["ABPWSSTA"].ToString(); 
          or1.Parameters.Add("ABPAPSTA", OracleType.NVarChar).Value = dwData["ABPAPSTA"].ToString(); 
          or1.Parameters.Add("ABPRZSTA", OracleType.NVarChar).Value = dwData["ABPRZSTA"].ToString(); 
          or1.Parameters.Add("ABPWPSTA", OracleType.NVarChar).Value = dwData["ABPWPSTA"].ToString(); 
          or1.Parameters.Add("ABPWBSTA", OracleType.NVarChar).Value = dwData["ABPWBSTA"].ToString(); 
          or1.Parameters.Add("ABPABSTA", OracleType.NVarChar).Value = dwData["ABPABSTA"].ToString(); 
          or1.Parameters.Add("PEND", OracleType.NVarChar).Value = dwData["PEND"].ToString(); 
          or1.Parameters.Add("FENDDAT", OracleType.NVarChar).Value = dwData["FENDDAT"].ToString(); 
          or1.Parameters.Add("FYEAR", OracleType.NVarChar).Value = dwData["FYEAR"].ToString(); 
          or1.Parameters.Add("FMONTH", OracleType.NVarChar).Value = dwData["FMONTH"].ToString(); 
          or1.Parameters.Add("FDAY", OracleType.NVarChar).Value = dwData["FDAY"].ToString(); 
          or1.Parameters.Add("FQUARTER", OracleType.NVarChar).Value = dwData["FQUARTER"].ToString(); 
          or1.Parameters.Add("PFCOST", OracleType.NVarChar).Value = dwData["PFCOST"].ToString(); 
          or1.Parameters.Add("PMCOST", OracleType.NVarChar).Value = dwData["PMCOST"].ToString(); 
          or1.Parameters.Add("PMBOMCOST", OracleType.NVarChar).Value = dwData["PMBOMCOST"].ToString(); 
          or1.Parameters.Add("PRODCOST", OracleType.NVarChar).Value = dwData["PRODCOST"].ToString(); 
          or1.Parameters.Add("PROFIT", OracleType.NVarChar).Value = dwData["PROFIT"].ToString(); 
          or1.Parameters.Add("ARTCOSTKG", OracleType.NVarChar).Value = dwData["ARTCOSTKG"].ToString(); 
          or1.Parameters.Add("ARTCOSTMTR", OracleType.NVarChar).Value = dwData["ARTCOSTMTR"].ToString(); 
          or1.Parameters.Add("ARTCOST", OracleType.NVarChar).Value = dwData["ARTCOST"].ToString(); 
          or1.Parameters.Add("FOK", OracleType.NVarChar).Value = dwData["FOK"].ToString(); 
          or1.Parameters.Add("RTIME", OracleType.NVarChar).Value = dwData["RTIME"].ToString(); 
          or1.Parameters.Add("RCOST", OracleType.NVarChar).Value = dwData["RCOST"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
